<?php
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Auth\Authenticatable;
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\Hash;

/**
 * 管理员
 *
 * @SWG\Model(id="Admin")
 * @SWG\Property(name="id",type="integer",description="主键索引")
 */
class Admin extends Model implements AuthenticatableContract
{
	use Authenticatable;

	protected $table = 'admins';

	public static function boot()
	{
		parent::boot();

		static::saving(function ($model)
		{
            // 保存的时候自动对密码进行加密。
            if (isset($model->password) && Hash::needsRehash($model->password)) {
                $model->password = Hash::make($model->password);
            }

		});
	}

	/**
	 * email 转为string类型
	 *
	 */
	public function getEmailAttribute()
	{
		return (string) $this->attributes['email'];
	}

}
